#ifndef _SYNMIXER_H
#define _SYNMIXER_H

#include "syncommon.h"
#include "synchannel.h"
#include "synvoice.h"
#include "synfx.h"
#include "syncompressor.h"

namespace Synth
{

class Mixer {
	enum {
		VOICEPOOLSIZE = 30
	};
	Channel channels[16];
	Voice voicepool[VOICEPOOLSIZE];
	int timeStamp;
	Reverb lreverb, rreverb;
	Delay ldelay, rdelay;
	chunkware_simple::SimpleCompRms comp;
	DownsamplingFilter ds_l, ds_r;

public:
	char globalParams[gp_NumGlobalParams];

#ifndef STREAMLINE
	float VU[16][2];
	float vu[2];
#endif
	Mixer();
	void Init(const unsigned char *ptr);
	Channel &GetChannel(int i) { return channels[i]; }
	Voice *AllocVoice(Channel *chan, int note);
	void ResetGlobalParameters();
	void SilenceReverbs() {lreverb.Silence(); rreverb.Silence();}
	void StopVoice(const Channel *chan, int note);
	void StopVoiceGroup(const Channel *chan, int group);
	void Render(Block leftBuf, Block rightBuf);
	void RenderOversample(Block leftBuf, Block rightBuf);

#ifndef STREAMLINE
	void DoMIDICmd(const unsigned char *cmd);
#endif
	void DoFakeMIDICmd(int channel, int command, int value1, int value2);				
	inline void SetGlobalParam(int param, int value) {
		globalParams[param-gp_Volume] = value;
	}
	inline int GetGlobalParam(int param) const {
		return globalParams[param - gp_Volume];
	}
	void StopAllVoices();
	int GetNumActiveVoicesFromChannel(int chan) const;
	int GetMaxVoices() {return VOICEPOOLSIZE;}
	int GetTimeStamp() const {return timeStamp;}
	const Voice &GetVoice(int i) const {return voicepool[i];}
};

}  // namespace

#endif